package com.aiyige.page.discovery.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.aiyige.utils.ListUtil;

import java.util.LinkedList;
import java.util.List;

public class ActivityData implements Parcelable {
    String coverUrl;
    String activityDesc;
    String sourceId;
    String activityTitle;

    public ActivityData() {
    }

    private ActivityData(Builder builder) {
        setCoverUrl(builder.coverUrl);
        setActivityDesc(builder.activityDesc);
        setSourceId(builder.sourceId);
        setActivityTitle(builder.activityTitle);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        this.coverUrl = coverUrl;
    }

    public String getActivityDesc() {
        return activityDesc;
    }

    public void setActivityDesc(String activityDesc) {
        this.activityDesc = activityDesc;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public String getActivityTitle() {
        return activityTitle;
    }

    public void setActivityTitle(String activityTitle) {
        this.activityTitle = activityTitle;
    }

    public static final class Builder {
        private String coverUrl;
        private String activityDesc;
        private String sourceId;
        private String activityTitle;

        private Builder() {
            coverUrl = "";
            activityDesc = "";
            sourceId = "";
            activityTitle = "";
        }

        public Builder coverUrl(String val) {
            coverUrl = val;
            return this;
        }

        public Builder activityDesc(String val) {
            activityDesc = val;
            return this;
        }

        public Builder sourceId(String val) {
            sourceId = val;
            return this;
        }

        public Builder activityTitle(String val) {
            activityTitle = val;
            return this;
        }

        public ActivityData build() {
            return new ActivityData(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.coverUrl);
        dest.writeString(this.activityDesc);
        dest.writeString(this.sourceId);
        dest.writeString(this.activityTitle);
    }

    protected ActivityData(Parcel in) {
        this.coverUrl = in.readString();
        this.activityDesc = in.readString();
        this.sourceId = in.readString();
        this.activityTitle = in.readString();
    }

    public static final Creator<ActivityData> CREATOR = new Creator<ActivityData>() {
        @Override
        public ActivityData createFromParcel(Parcel source) {
            return new ActivityData(source);
        }

        @Override
        public ActivityData[] newArray(int size) {
            return new ActivityData[size];
        }
    };

    public static List<String> extractIdList(List<ActivityData> activityDataList) {
        List<String> idList = new LinkedList<>();
        if (ListUtil.isEmpty(activityDataList)) return idList;
        for (ActivityData data : activityDataList) {
            if (TextUtils.isEmpty(data.getSourceId())) continue;
            idList.add(data.getSourceId());
        }
        return idList;
    }

    public static List<ActivityData> parse(List<ActivityResp> activityRespList) {
        List<ActivityData> activityDataList = new LinkedList<>();
        if (ListUtil.isEmpty(activityRespList)) return activityDataList;
        try {
            for (ActivityResp item : activityRespList) {
                activityDataList.add(ActivityData.newBuilder()
                        .activityDesc(item.getRemark())
                        .activityTitle(item.getName())
                        .sourceId(item.getId())
                        .coverUrl(item.getCover())
                        .build());
            }
        } catch (Exception e) {

        }
        return activityDataList;
    }

}
